package com.dongzili.query.common.config.mybatisplus;

import cn.hutool.extra.spring.SpringUtil;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.IService;

public class MybatisPlusUtil {
    /**
     * 获取Service
     * @param t
     * @return
     */
    public static <T> IService<T> getService(final Class<T> t) {
        return SpringUtil.getBean(getBeanName(t) + "AutoServiceImpl");
    }

    /**
     * 获取Mapper
     * @param t
     *     @return
     */
    public static <T> BaseMapper<T> getMapper(final Class<T> t) {
        return SpringUtil.getBean(getBeanName(t) + "AutoMapper");
    }

    /**
     * 获取bean名称
     * @param t
     * @return
     */
    private static <T> String getBeanName(final Class<T> t) {
        return t.getSimpleName().substring(0, 1).toLowerCase() + t.getSimpleName().substring(1);
    }
}